package com.yaozheng.vocationaltraining.service.impl.checkpoints_trip;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.checkpoints_trip.ICheckpointsTripQuestionView;
import com.yaozheng.vocationaltraining.service.checkpoints_trip.CheckpointsTripQuestionService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * 获取答案
 */
@EBean
public class CheckpointsTripQuestionServiceImpl implements CheckpointsTripQuestionService {
    ICheckpointsTripQuestionView iCheckpointsTripQuestionView;

    @Override
    public void init(ICheckpointsTripQuestionView iCheckpointsTripQuestionView) {
        this.iCheckpointsTripQuestionView = iCheckpointsTripQuestionView;
    }

    @Background
    @Override
    public void getQuestionList(int step) {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/exam/advanced?step=" + step,
                    iCheckpointsTripQuestionView.getToken(), new BaseView(iCheckpointsTripQuestionView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iCheckpointsTripQuestionView.getQuestionListSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iCheckpointsTripQuestionView.getQuestionListError(error);
                        }

                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iCheckpointsTripQuestionView.isResponseResult()) {
                iCheckpointsTripQuestionView
                        .getQuestionListError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
